In [1]:
# -*- coding: utf-8 -*-
"""
QuantEcon Notebook
Copyright (c) 2016 @myuuuuun
Released under the MIT license.
"""
%matplotlib inline
import math
import numpy as np
In [2]:
from random import normalvariate
import matplotlib.pyplot as plt
ts_length = 100
epsilon_values = [] # An empty list
for i in range(ts_length):
e = normalvariate(0, 1)
epsilon_values.append(e)
plt.plot(epsilon_values, 'purple')
plt.show()
In [24]:
x = []
x.append("aiueo")
x.append(3)
x
Out[24]:
In [27]:
array = [2, 3, 4, False, True, "aiueo"]
for i in range(3):
print(array.pop())
print(array)
In [29]:
array = [2, 3, 4, False, True, "aiueo"]
array.append("aaa")
array
Out[29]:
In [31]:
array = [2, 3, 4, False, True, "aiueo"]
for elem in array:
print(elem)
In [33]:
array = [2, 3, 4, False, True, "aiueo"]
for i in range(4):
print(i, "番目の要素は: ", array[i])
In [35]:
animals = ['dog', 'cat', 'fish']
for animal in animals:
print("The plural of " + animal + " is " + animal + "s")
In [42]:
s = 0
i = 1
while i <= 10:
s += i
i += 1
print(s)
In [44]:
s = 0
i = 1
while True:
s += i
i += 1
if i > 10:
break
print(s)
In [49]:
def your_favorite_name(argument):
return argument
In [50]:
print( your_favorite_name("太郎") )
In [51]:
# 引数の2乗を計算する
def x_2(x):
s = x * x
return s
In [53]:
y = x_2(0.3)
print(y)
In [15]:
from random import normalvariate, uniform
def generate_data(n, generator_type=None):
print(generator_type)
epsilon_values = []
for i in range(n):
if generator_type == 'U':
e = uniform(0, 1)
else:
e = normalvariate(0, 1)
epsilon_values.append(e)
return epsilon_values
data = generate_data(100, "U")
plt.plot(data, 'b.')
plt.show()
In [16]:
data = generate_data(100)
plt.plot(data, 'b.')
plt.show()
In [17]:
x = -10
s = 'negative' if x < 0 else 'nonnegative'
print(s)
In [18]:
x = 3.3
s = 'negative' if x < 0 else 'nonnegative'
print(s)
In [19]:
x = 20
if x < 0:
print("negative")
else:
print("nonnegative")
In [24]:
x = -0.9
s = 'negative' if x < 0 else 'zero' if x == 0 else 'positive'
print(s)
In [33]:
from random import uniform, normalvariate, weibullvariate
import matplotlib.pyplot as plt
def generate_data(n, generator_type=uniform):
print(uniform)
epsilon_values = []
for i in range(n):
e = generator_type(0, 1)
epsilon_values.append(e)
return epsilon_values
data = generate_data(100)
plt.plot(data, 'b-')
plt.show()
In [34]:
array = [0, -3, 2**10, 1000]
max(array)
Out[34]:
In [35]:
m = max
m(array)
Out[35]:
In [36]:
m
Out[36]:
In [37]:
animals = ['dog', 'cat', 'bird']
plurals = [animal + 's' for animal in animals]
print(plurals)
In [39]:
plurals = []
for animal in animals:
plurals.append(animal + "s")
print(plurals)
In [41]:
array = list(range(1, 10))
print(array)
In [47]:
doubles = [pow(x, 3) for x in array]
print(doubles)
In [50]:
import math
doubles = [x**math.sqrt(2) for x in array]
print(doubles)
In [53]:
epsilon_values = [uniform(0, 1) for i in range(10)]
print(epsilon_values)
In [ ]: